import { defineStore } from 'pinia'
import { reqC1, reqC2, reqC3 } from '@/api/product/attr'
import type { CategoryResData } from '@/api/product/attr/type'
import type { categoryState } from '../types'
let useCategoryStore = defineStore('Category', {
  state: (): categoryState => {
    return {
      c1: '',
      c1Arr: [],
      c2: '',
      c2Arr: [],
      c3: '',
      c3Arr: []
    }
  },
  actions: {
    // 请求获取一级分类
    async getC1() {
      let result: CategoryResData = await reqC1()
      if (result.code == 200)
        this.c1Arr = result.data
    },
    // 请求获取二级分类
    async getC2(c1: number) {
      let result : CategoryResData = await reqC2(c1)
      if (result.code == 200)
        this.c2Arr = result.data
    },
    // 请求获取二级分类
    async getC3(c2: number) {
      let result : CategoryResData = await reqC3(c2)
      if (result.code == 200)
        this.c3Arr = result.data
    },
  },
})

export default useCategoryStore
